import { defineStore } from 'pinia'
import { ref } from 'vue'
import * as systemApi from '@/api/system'

export const useSystemStore = defineStore('system', () => {
  const loading = ref(false)

  // 获取系统设置
  const fetchSystemSettings = async () => {
    loading.value = true
    try {
      return await systemApi.getSystemSettings()
    } finally {
      loading.value = false
    }
  }

  // 更新基础设置
  const updateBasicSettings = async (data: any) => {
    return await systemApi.updateBasicSettings(data)
  }

  // 更新业务设置
  const updateBusinessSettings = async (data: any) => {
    return await systemApi.updateBusinessSettings(data)
  }

  // 更新通知设置
  const updateNotificationSettings = async (data: any) => {
    return await systemApi.updateNotificationSettings(data)
  }

  // 更新安全设置
  const updateSecuritySettings = async (data: any) => {
    return await systemApi.updateSecuritySettings(data)
  }

  // 获取系统信息
  const fetchSystemInfo = async () => {
    return await systemApi.getSystemInfo()
  }

  // 获取在线用户
  const fetchOnlineUsers = async () => {
    return await systemApi.getOnlineUsers()
  }

  // 踢出用户
  const kickUser = async (userId: number) => {
    return await systemApi.kickUser(userId)
  }

  // 测试通知
  const testNotification = async (type: string) => {
    return await systemApi.testNotification(type)
  }

  return {
    loading,
    fetchSystemSettings,
    updateBasicSettings,
    updateBusinessSettings,
    updateNotificationSettings,
    updateSecuritySettings,
    fetchSystemInfo,
    fetchOnlineUsers,
    kickUser,
    testNotification
  }
})